package com.boomcat.boomcat.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class CaptchaGenerator {

    @Autowired
    private CacheManager cacheManager;

    public String generateCaptchaCode(String key) {

        //generate code
        Random random = new Random();
        Integer verificationCode = random.nextInt(899999) + 100000;
        String captcha = verificationCode.toString(); // 假设这里是生成的验证码

        cacheManager.getCache("captcha").put(key, captcha);
        return captcha;
    }

    public String getCaptchaFromCache(String key) {
        return cacheManager.getCache("captcha").get(key, String.class);
    }
}
